<template>
	<view class="box-main">

		<view class="box-center mlr wfc flex ac jc fc">
			<view>
				<image src="https://yjgs.jsonbug.com/test/wx_logo.png" style="width: 220px;height: 45px;"></image>
			</view>
			<view style="margin-top: 80rpx;margin-bottom: 50rpx;">
				<text class="fw fs-38">当前使用的账号</text>
			</view>
			<view v-if="isLogin" class="flex ac">
				<image :src="userInfo.avatar || ''" style="width: 80rpx;height: 80rpx;border-radius: 100%;"></image>
				<text class="ml-10">{{userInfo.nickname || '--'}}</text>
			</view>
			<view v-else class="flex ac">
				<image src="/static/images/f.png" style="width: 80rpx;height: 80rpx;border-radius: 100%;"></image>
				<text class="ml-10">请先登录</text>
			</view>
		</view>

		<view @click="authClick" class="box-btn shadow-1">
			<text>{{isLogin ? '确认授权' : '登录后在授权'}}</text>
		</view>

		<view class="box-text">
			<view style="color: #9A999C;">
				授权的作用：
			</view>
			<view class="mt-20 ls-2" style="color: #9A999C;">
				1.授权以后用户购买商品自动获取消息推送
			</view>
			<view class="mt-20 ls-2" style="color: #9A999C;">
				2.授权以后可以创建子商城/名片商城等等
			</view>
		</view>

	</view>
</template>

<script>
	import {
		saveUserMerchant
	} from "@/api/extend.js"
	import {
		mapGetters
	} from "vuex";
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		configMap
	} from '@/utils';
	export default {
		data() {
			return {
				mer_id: ''
			}
		},
		computed: configMap({
			mer_intention_open: 0,
		}, mapGetters(['isLogin', 'uid', 'userInfo'])),
		onLoad(options) {
			if (options.scene) {
				let option = decodeURIComponent(options.scene);
				let param = this.$timer.getQueryParams(option)
				if (param.mer_id) {
					this.mer_id = param.mer_id
				}
			}
		},
		methods: {
			authClick() {

				if (!this.isLogin) {
					toLogin();
					return
				}

				saveUserMerchant({
					uid: this.uid,
					mer_id: this.mer_id,
				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none',
						duration: 2000
					})

					if (res.status == 200) {
						setTimeout(() => {
							uni.showToast({
								title: '即将返回到首页'
							})
						}, 2000)
						
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/index/index'
							})
						}, 3000)
					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.box-text {
		margin-top: 80rpx;
		margin-left: 20rpx;
	}

	.box-btn {
		margin-top: 80rpx;
		margin-left: 20rpx;
		width: calc(100% - 40rpx);
		height: 100rpx;
		line-height: 100rpx;
		border-radius: 12rpx;
		background-color: #02029F;
		color: white;
		text-align: center;
		font-size: 36rpx;
	}

	.box-center {
		margin-top: 10vh;
	}

	.box-main {
		padding: 20rpx;
		width: 100%;
		height: 100vh;
		box-sizing: border-box;
		background-color: white;
	}
</style>